package pe.edu.upc.e41a.javasoft.dao;

import java.util.List;

import pe.edu.upc.e41a.javasoft.domain.Producto;


import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;



	@Repository(value = "ProductoDao")
	public class ProductoDaoImpl implements ProductoDao {

	    private EntityManager em = null;

	    /*
	     * Sets the entity manager.
	     */
	    @PersistenceContext
	    public void setEntityManager(EntityManager em) {
	        this.em = em;
	    }

	   	    
	    @Transactional(readOnly = true)
		@Override
		public List<Producto> getProductoList() {
	    	return em.createQuery("select p from Producto p order by p.id").getResultList();
		}
	    
	    @Transactional(readOnly = false)
		@Override
		public void saveProducto(Producto producto) {
	    	em.merge(producto);
			
		}




}
